package org.ilc.socketserver;

import org.ilc.push.IRequest;
import org.ilc.push.ISession;

/**
 * @author malongbo
 */
public class Request implements IRequest {
    private Header header;
    private byte[] body;
    private String remoteAddress=null;
    private ISession session;

    public void setHeaderData(byte[] bytes) throws Exception{
        header = new Header (bytes);
    }

    @Override
    public Header getHeader() {
        return this.header;
    }

    @Override
    public byte[] getBody() {
        return this.body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    @Override
    public String getHeader(String key) {
        return null != header ? header.getHeader(key) : null;
    }

    @Override
    public String getRemoteAddress() {
        return this.remoteAddress;
    }

    public void setRemoteAddress(String remoteAddress) {
        this.remoteAddress = remoteAddress;
    }

    @Override
    public ISession getSession() {
        return this.session;
    }

    public void setSession(ISession session) {
        this.session = session;
    }

    @Override
    public void destroy() {
        if(null != this.header){
            this.header.destroy();
            this.header=null;
        }
        this.remoteAddress=null;
        this.body=null;
    }
}
